package org.example;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class demoRedisSet {
    public static void test(Jedis jedis){
        System.out.println("sadd 和 smembers");
        jedis.sadd("key","111","222","333");
        Set<String> result=jedis.smembers("key");
        System.out.println(result);
        jedis.del("key");
        System.out.println(jedis.smembers("key"));
    }

    public static void test1(Jedis jedis){
        System.out.println(" sismember");
        jedis.sadd("key","111","222","333");
      boolean result=jedis.sismember("key","111");
        System.out.println(result);
        jedis.del("key");
        System.out.println(jedis.sismember("key","111"));
    }
    public static void test2(Jedis jedis){
        System.out.println(" scard");
        jedis.sadd("key","111","222","333");

        long result=jedis.scard("key");
        System.out.println(result);
    }
    public static void test3(Jedis jedis){
        System.out.println(" spop");
        jedis.sadd("key","111","222","333","444");
        String key = jedis.spop("key");

        System.out.println(key);
    }
    public static void test4(Jedis jedis){
        System.out.println(" sinter");
        jedis.sadd("key","111","222","333","444");
        jedis.sadd("key2","111","444");
        Set<String> sinter = jedis.sinter("key", "key2");
        System.out.println(sinter);
    }
    public static void test5(Jedis jedis){
        System.out.println(" sinterstore");
        jedis.sadd("key","111","222","333","444");
        jedis.sadd("key2","111","444");
        long sinterslong = jedis.sinterstore("key3", "key2", "key");
        Set<String> key3 = jedis.smembers("key3");
        System.out.println(sinterslong+" "+key3);
    }



    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test(jedis);
//            test1(jedis);
//            test3(jedis);
            test5(jedis);
        }

    }
}
